<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .login-container {
            border: 1px solid #ccc;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px #ccc;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
        }
        input[type="text"], input[type="password"] {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        button {
            width: 100%;
            padding: 10px;
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        button:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
<div class="login-container">
    <div class="form-group">
        <label for="name">姓名</label>
        <input type="text" id="name" placeholder="请输入姓名">
    </div>
    <div class="form-group">
        <label for="user_name">用户名</label>
        <input type="text" id="user_name" placeholder="请输入用户名">
    </div>
    <div class="form-group">
        <label for="pass_word">密码</label>
        <input type="password" id="pass_word" placeholder="请输入密码">
    </div>
    <button onclick="login()">登录</button>
</div>

<script>
    async function login() {
        const name = document.getElementById('name').value;
        const user_name = document.getElementById('user_name').value;
        const pass_word = document.getElementById('pass_word').value;

        const response = await fetch('http://127.0.0.1:3200/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                name: name,
                user_name: user_name,
                pass_word: pass_word
            })
        });

        const data = await response.json();

        if (data.code === 200) {
            alert('登录成功，token: ' + data.data.token);
            // 这里可以添加进一步的处理，比如将token存储到localStorage或跳转到主页
        } else {
            alert('登录失败: ' + data.msg);
        }
    }
</script>
</body>
</html>